home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ddj0190.arc / RAHNER.EXE / GEN_ASM.ASM < prev    next >
Assembly Source File  |  1989-09-21  |  9KB  |  378 lines

  1.     comment \
  2.              Sprite Circle Handler
  3.         Copyright (c) February 1989, Ryu Consulting, Inc.
  4.             (916) 722 - 1939 anytime
  5.  
  6.             Written by Rahner James, CS
  7.  
  8.         \
  9.  
  10.     .model    small, c
  11.  
  12.  
  13. ; ****************************************************************************
  14.  
  15. ;    EQUATES
  16.  
  17. ; ****************************************************************************
  18.  
  19. MAX_SPRITES    equ    50
  20.  
  21.  
  22. ; ****************************************************************************
  23.  
  24. ;    STRUCTURES
  25.  
  26. ; ****************************************************************************
  27.  
  28. sprite_structure struc
  29. animate_ptr    dw    0,0
  30. sprite_width    dw    0        ; Width in words
  31. sprite_height    dw    0        ; Height in pixels
  32. sprite_body    db    ?
  33. sprite_structure ends
  34.  
  35.  
  36. sprite_node    struc
  37. x        dw    0
  38. y        dw    0
  39. depth        dw    0
  40. pre_x        dw    0
  41. pre_y        dw    0
  42. dest_x        dw    0
  43. dest_y        dw    0
  44. adder_x    dw    0
  45. adder_y    dw    0
  46. sprite_ptr    dw    0,0
  47. next_node    dw    0
  48. sprite_node    ends
  49.  
  50.  
  51. .data
  52. ; ****************************************************************************
  53.  
  54. ;    DATA VARIABLES and EXTERNAL DEFINITIONS
  55.  
  56. ; ****************************************************************************
  57.  
  58. extrn    done_page_flip:byte, do_page_flip:byte
  59. extrn    min_x:word, min_y:word, max_y:word, max_x:word
  60.  
  61. first_sprite    dw    0
  62. public    sprite_list
  63. sprite_list    sprite_node    MAX_SPRITES dup(<>)
  64.  
  65. pre_max_x    dw    639
  66. pre_max_y    dw    199
  67. pre_min_x    dw    0
  68. pre_min_y    dw    0
  69.  
  70.  
  71. .code
  72. ; ****************************************************************************
  73.  
  74. ;    ROUTINES and EXTERNAL CODE DEFINITIONS
  75.  
  76. ; ****************************************************************************
  77.  
  78. extrn    do_background:near, put_sprite:near
  79.  
  80.  
  81. ; ****************************************************************************
  82. ;
  83. ; void DO_SPRITE_LIST( void )
  84. ; Sets up the sprites on the unviewed back page
  85. ; Given:
  86. ;    A sprite list has been created and is stored in the array SPRITE_LIST
  87. ; Returns:
  88. ;    If DONE_PAGE_FLIP is 0, no processing is done
  89. ;    else all sprites in the sprite list are put on the non-visual page
  90. ;     then DONE_PAGE_FLIP is set to 0 and DO_PAGE_FLIP is set to -1
  91.  
  92. do_sprite_list proc uses si
  93.  
  94.     cmp    done_page_flip, 0    ; See if we need to do this
  95.     jnz    @F
  96.     jmp    done
  97.  
  98. @@:    call    do_background
  99.  
  100.     mov    ax, pre_max_x
  101.     mov    max_x, ax
  102.     mov    ax, pre_max_y
  103.     mov    max_y, ax
  104.     mov    ax, pre_min_x
  105.     mov    min_x, ax
  106.     mov    ax, pre_min_y
  107.     mov    min_y, ax
  108.  
  109.     xor    ax, ax            ; Clear out some variables
  110.     mov    pre_max_x, ax
  111.     mov    pre_max_y, ax
  112.     dec    ax
  113.     mov    pre_min_x, ax
  114.     mov    pre_min_y, ax
  115.  
  116.     mov    si, first_sprite    ; SI -> sprite node to start with
  117. next_sprite:
  118.     or    si, si            ; See if this is a NULL pointer
  119.     jnz    @F
  120.     jmp    almost_done
  121.  
  122. @@:    mov    ax, [si].x
  123.     mov    [si].pre_x, ax
  124.  
  125.     cmp    [si].dest_x, ax        ; See if we are already there
  126.     je    no_add_x        ; Skip if we are
  127.     mov    cx, [si].dest_x        ; Get our absolute value
  128.     sub    cx, [si].x
  129.     jnc    @F
  130.     neg    cx
  131. @@:    add    ax, [si].adder_x
  132.     mov    [si].x, ax
  133.     sub    ax, [si].dest_x
  134.     jnc    @F
  135.     neg    ax
  136. @@:    cmp    cx, ax
  137.     jnc    no_add_x
  138.     mov    ax, [si].dest_x
  139.     mov    [si].x, ax
  140. no_add_x:
  141.     mov    ax, [si].y
  142.     mov    [si].pre_y, ax
  143.  
  144.     cmp    [si].dest_y, ax        ; See if we are already there
  145.     je    no_add_y        ; Skip if we are
  146.     mov    cx, [si].dest_y        ; Get our absolute value
  147.     sub    cx, [si].y
  148.     jnc    @F
  149.     neg    cx
  150. @@:    add    ax, [si].adder_y
  151.     mov    [si].y, ax
  152.     sub    ax, [si].dest_y
  153.     jnc    @F
  154.     neg    ax
  155. @@:    cmp    cx, ax
  156.     jnc    no_add_y
  157.     mov    ax, [si].dest_y
  158.     mov    [si].y, ax
  159. no_add_y:
  160.     cmp    [si].y, 200        ; See if beyond bottom line
  161.     jnc    pre_next_sprite
  162.     mov    ax, [si].x        ; See if we need to update some things
  163.     cmp    ax, 640            ; See if beyond right column
  164.     jnc    pre_next_sprite
  165.     cmp    ax, pre_min_x        ; See if pre_x < min_x
  166.     jnc    @F            ; Skip if not
  167.     mov    pre_min_x, ax        ; Update with new MIN_X
  168.  
  169. @@:    mov    ax, [si].y        ; See if need to update min_y
  170.     cmp    ax, pre_min_y
  171.     jnc    @F
  172.     mov    pre_min_y, ax
  173.  
  174. @@:    les    bx, dword ptr [si].sprite_ptr    ; ES:BX -> sprite structure
  175.  
  176.     mov    ax, es:[bx].sprite_width
  177.     inc    ax
  178.     if    (@Cpu AND 2)
  179.     shl    ax, 4            ; AX = AX * 16
  180.     else
  181.     rept    4
  182.     add    ax, ax
  183.     endm
  184.     endif
  185.     add    ax, [si].x
  186.     cmp    pre_max_x, ax        ; See if > max_x
  187.     jnc    @F            ; Jump if not
  188.     mov    pre_max_x, ax        ; Assume we are going to save it
  189.  
  190. @@:    mov    ax, es:[bx].sprite_height
  191.     add    ax, [si].y
  192.     cmp    pre_max_y, ax        ; See if > max_x
  193.     jnc    @F            ; Jump if not
  194.     mov    pre_max_y, ax        ; Assume we are going to save it
  195.  
  196. @@:    push    es            ; Set up for call to put_sprite()
  197.     push    bx
  198.     push    [si].y
  199.     push    [si].x
  200.     call    put_sprite
  201.     add    sp, 4            ; Clear the stack
  202.     pop    bx            ; ES:BX -> sprite pointer
  203.     pop    es
  204.     les    bx, dword ptr es:[bx].animate_ptr
  205.     mov    [si].sprite_ptr, bx
  206.     mov    [si].sprite_ptr+2, es
  207.  
  208. pre_next_sprite:
  209.     mov    si, [si].next_node    ; SI -> next sprite node in line
  210.     jmp    next_sprite
  211.  
  212. almost_done:
  213.     mov    ax, pre_max_x
  214.     cmp    ax, 640
  215.     jb    @F
  216.     mov    ax, 639
  217.     mov    pre_max_x, ax
  218. @@:    cmp    pre_min_x, ax
  219.     jb    @F
  220.     dec    ax
  221.     mov    pre_min_x, ax
  222. @@:    mov    ax, pre_max_y
  223.     cmp    ax, 200
  224.     jb    @F
  225.     mov    ax, 199
  226.     mov    pre_max_y, ax
  227. @@:    cmp    pre_min_y, ax
  228.     jb    @F
  229.     mov    pre_min_y, ax
  230.  
  231. @@:    mov    done_page_flip, 0
  232.     mov    do_page_flip, -1
  233.  
  234. done:    ret
  235. do_sprite_list endp
  236.  
  237.  
  238. ; ****************************************************************************
  239. ;
  240. ; void CLEAR_SPRITE_LIST( void )
  241. ; Zeros out the present sprite list
  242. ; Given:
  243. ;    nothing
  244. ; Returns:
  245. ;    FIRST_SPRITE and SPRITE_LIST array are zeroed
  246.  
  247. clear_sprite_list proc uses di
  248.  
  249.     cld
  250.     mov    di, offset sprite_list
  251.     mov    ax, ds
  252.     mov    es, ax
  253.     xor    ax, ax
  254.     mov    first_sprite, ax
  255.     mov    cx, (MAX_SPRITES * (size sprite_node))/2
  256.     rep    stosw
  257.  
  258.     ret
  259. clear_sprite_list endp
  260.  
  261.  
  262. ; ****************************************************************************
  263. ;
  264. ; int INSERT_SPRITE( ui X1,ui Y1, ui D_X,ui D_Y, ui PLUS_X,ui PLUS_Y,
  265. ;               ui THE_DEPTH, sprite_structure far *SPRITE )
  266. ; Inserts the first sprite of a sprite circle into the linked list of circles
  267. ; Given:
  268. ;    X1,Y1 = pixel location of the upper left corner of the sprite
  269. ;    D_X,D_Y = pixel location of the destination of the sprite
  270. ;    PLUS_X,PLUS_Y = pixels the sprite moves every page flip
  271. ;    THE_DEPTH = apparent distance of the sprite from the viewer
  272. ;    SPRITE -> sprite to insert
  273. ; Returns:
  274. ;    If 0, sprite pointer was inserted in the array
  275. ;    else !0 if there is no room
  276.  
  277. insert_sprite proc uses si, x1:word,y1:word, d_x:word,d_y:word,\
  278.                 plus_x:word,plus_y:word, the_depth:word,\
  279.                 sprite:dword
  280.  
  281.     mov    cx, MAX_SPRITES
  282.     mov    bx, (offset sprite_list) - (size sprite_node)
  283. @@:    add    bx, size sprite_node
  284.     mov    ax, [bx].sprite_ptr    ; See if this has been set yet
  285.     or    ax, [bx].sprite_ptr+2
  286.     loopnz    @B
  287.     jnz    done_bad
  288.  
  289.     les    ax, sprite        ; ES:AX -> sprite location
  290.     mov    [bx].sprite_ptr, ax    ; Save it
  291.     mov    [bx].sprite_ptr+2, es
  292.  
  293.     mov    ax, x1            ; Set up the structure
  294.     mov    [bx].x, ax
  295.     mov    [bx].pre_x, ax
  296.     mov    ax, y1
  297.     mov    [bx].y, ax
  298.     mov    [bx].pre_y, ax
  299.     mov    ax, d_x
  300.     mov    [bx].dest_x, ax
  301.     mov    ax, d_y
  302.     mov    [bx].dest_y, ax
  303.     mov    ax, plus_x
  304.     mov    [bx].adder_x, ax
  305.     mov    ax, plus_y
  306.     mov    [bx].adder_y, ax
  307.     mov    ax, the_depth
  308.     mov    [bx].depth, ax        ; This is used in the following loop
  309.     mov    dx, bx            ; Save this s[rite entry for later
  310.  
  311.     mov    si, first_sprite    ; SI -> sprite furthest from the viewer
  312.     mov    bx, offset first_sprite    ; BX -> previous sprite entry
  313.     mov    cx, MAX_SPRITES
  314. @@:    or    si, si            ; See if it's a NULL ptr
  315.     jz    @F            ; Skip out if it is
  316.     cmp    ax, [si].depth        ; See if farther from observer
  317.     jnc    @F
  318.     mov    bx, si            ; BX = this pointer
  319.     mov    si, [si].next_node    ; SI -> next sprite node in line
  320.     loop    @B
  321. done_bad:
  322.     mov    ax, -1            ; Indicate we had a problem
  323.     jmp    short done
  324.  
  325. @@:    xchg    si, dx            ; SI -> sprite_list[i]
  326.     mov    [si].next_node, dx
  327.     cmp    bx, offset first_sprite
  328.     jne    @F
  329.     mov    [bx], si
  330.     jmp    short done_good
  331. @@:    mov    [bx].next_node, si
  332. done_good:
  333.     xor    ax, ax
  334. done:    ret
  335.  
  336. insert_sprite endp
  337.  
  338.  
  339. ; ****************************************************************************
  340. ;
  341. ; void ADD_SPRITE( sprite_structure far *DEST, far *SOURCE )
  342. ; Adds a self-relative sprite motion to the end of a sprite circle
  343. ; Given:
  344. ;    DEST -> sprite circle header
  345. ;    SOURCE -> sprite to add on
  346. ; Returns:
  347. ;    SOURCE is added to the end of the sprite linked list and the
  348. ;    circle ends are rejoined, may the circle be unbroken (ie Johnny Cash)
  349.  
  350. add_sprite proc uses si di ds, dest:dword, source:dword
  351.  
  352.     lds    si, dest
  353.     les    di, source
  354. next_sprite:
  355.     mov    ax, [si].animate_ptr    ; See if this is the end of the line
  356.     cmp    ax, word ptr dest
  357.     jne    @F
  358.     mov    ax, [si].animate_ptr+2
  359.     cmp    ax, word ptr dest+2
  360.     je    got_the_end
  361. @@:    lds    si, [si].animate_ptr
  362.     jmp    next_sprite
  363.  
  364. got_the_end:
  365.     mov    [si].animate_ptr, di
  366.     mov    [si].animate_ptr+2, es
  367.     mov    ax, word ptr dest
  368.     mov    es:[di].animate_ptr, ax
  369.     mov    ax, word ptr dest+2
  370.     mov    es:[di].animate_ptr+2, ax
  371.  
  372.     ret
  373. add_sprite endp
  374.  
  375.  
  376.     end
  377.  
  378.